package offer;

import java.util.ArrayList;
import java.util.Collections;

public class Offer6 {

    class Solution {
        public int[] reversePrint(ListNode head) {
            ArrayList<Integer> list = new ArrayList<>();

            ListNode cursor = head;
            while (cursor != null) {
                list.add(cursor.val);
                cursor = cursor.next;
            }

            Collections.reverse(list);
            int size = list.size();
            int[] ret = new int[size];
            for (int i = 0; i < size; i++) {
                ret[i] = list.get(i);
            }
            return ret;
        }
    }
}
